package com.egov.wrdmp.reporting.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.egov.wrdmp.reporting.dao.ExpenseDAO;
import com.egov.wrdmp.reporting.model.Expense;
import com.egov.wrdmp.reporting.model.Report;
@Repository
public class ExpenseDAOImpl implements ExpenseDAO{
	@Autowired
    private SessionFactory sessionFactory;
	
	@Transactional
	public void addExpense(Expense expense) {
		sessionFactory.getCurrentSession().save(expense);
		
	}

	@Transactional
	public List<Expense> listExpense() {
		
		return sessionFactory.getCurrentSession().createQuery("from Expense").list();
	}
	
	@Transactional
	public void removeExpense(Integer id) {
		Expense expense = (Expense) sessionFactory.getCurrentSession().load(
				Expense.class, id);
        if (null != expense) {
            sessionFactory.getCurrentSession().delete(expense);
        }
		
	}

}
